﻿namespace WebApplicationWorer
{
    public class MyWorker : IHostedService
    {
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _ = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
          
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }

        private void DoWork(object state)
        {
            Console.WriteLine("Running scheduled task..." + DateTime.Now);
        }
    }
}
